package com.guyj.baseapp.demo.imagepick;

import android.os.Bundle;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.widget.EditText;

import com.guyj.baseapp.R;
import com.guyj.common.base.BaseActivity;
import com.guyj.common.utils.AlertException;
import com.guyj.common.utils.ImagePickUtils;

import java.util.List;

import butterknife.Bind;
import butterknife.OnClick;
import cn.finalteam.galleryfinal.model.PhotoInfo;

/**
 * GalleryFinal的使用demo，需要在application中全局配置一次后使用
 * 具体内容可查看App类下的initImagePicker()方法
 * 考虑到多选和单选只是张数的区别，单选设置多选一张就行
 */
public class ImagePickActivity extends BaseActivity {

    @Bind(R.id.et_imagePick_num)
    EditText etImagePickNum;
    @Bind(R.id.recycler)
    RecyclerView recyclerView;
    ImagePickAdapter adapter;
    GridLayoutManager glm;

    @Override
    public int getContentViewId() {
        return R.layout.activity_image_pick;
    }

    @Override
    protected void initView(Bundle savedInstanceState) {
        setBack();
        setTitle("imagePicker");
    }

    @Override
    protected void initVariable() {
        glm=new GridLayoutManager(context,3);
        adapter=new ImagePickAdapter(recyclerView,R.layout.layout_griditem);
        recyclerView.setHasFixedSize(true);
        recyclerView.setLayoutManager(glm);
        recyclerView.setAdapter(adapter);
    }

    @Override
    protected void processLogic(Bundle savedInstanceState) {

    }

    @OnClick(R.id.tv_imagePick)
    public void onClick() {
        ImagePickUtils.openImagePick(Integer.valueOf(etImagePickNum.getText().toString().trim()), new ImagePickUtils.ImagePickListener() {
            @Override
            public void onHanlderSuccess(int requestCode, List<PhotoInfo> resultList) {
                adapter.setData(resultList);
            }

            @Override
            public void onHanlderFailure(int requestCode, String errorMsg) {
                throw new AlertException(errorMsg);
            }
        });
    }
}
